package com.zhuannimei.adapter;

import java.util.List;

import com.zhuannimei.R;
import com.zhuannimei.domain.ZnmList;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class AppAdapter extends BaseAdapter {
	private LayoutInflater lf;
	private List<ZnmList> znmLists;
	ListView lvContacts;
	private Context mContext;

	public AppAdapter(Context context, List<ZnmList> ZnmLists,
			ListView lvContacts) {
		this.lvContacts = lvContacts;
		this.znmLists = ZnmLists;
		mContext = context;
		lf = LayoutInflater.from(context);
	}

	public AppAdapter(Context context) {
		mContext = context;
		lf = LayoutInflater.from(context);

	}

	public void setContactsInfo(List<ZnmList> contactsInfo) {
		this.znmLists = contactsInfo;
	}

	public void setLvContacts(ListView lvContacts) {
		this.lvContacts = lvContacts;
	}

	@Override
	public int getCount() {
		return znmLists.size();
	}

	@Override
	public Object getItem(int position) {
		return znmLists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler holder = null;
		if (convertView != null) {
			holder = (ViewHodler) convertView.getTag();
		} else {
			convertView = lf.inflate(R.layout.apps_item_view, null);
			holder = new ViewHodler();
			holder.ivHeader = (ImageView) convertView
					.findViewById(R.id.iv_header);
			holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			holder.tvDesc = (TextView) convertView.findViewById(R.id.tv_desc);
			convertView.setTag(holder);
		}
		ZnmList cInfo = znmLists.get(position);
		String headUrl = cInfo.getImgPath();
		if (!TextUtils.isEmpty(headUrl)) {
			String id = cInfo.getAppId();
		}
		holder.tvName.setText(cInfo.getAppName());
		holder.tvDesc.setText(cInfo.getAppDesc());
		return convertView;

	};

	class ViewHodler {
		TextView tvName, tvDesc;
		ImageView ivHeader, ivGender;
	}
}
